<template>
	<view class="warrant">
		<view class="white">
			<view class="pictrue"></view>
			<view class="tip">您的信息和数据将受到保护</view>
			<button class="but" type="primary" @click="getUserProfile">授权并登录</button>
			<button @click="toIndex" style="margin-top: 30rpx;background: #eee;color: #5d8bf7;" class="but">取 消</button>
		</view>
		<view class="mask"></view>
	</view>
</template>

<script>
import { wxLogin } from '@/api/auth';
export default {
	data() {
		return {
			
		};
	},

	mounted() {
		
	},
	onLoad(options) {
		
	},
	onShow() {
		
	},
	methods: {
		getUserProfile(){
			uni.showLoading({
				title: '加载中...'
			});
			uni.getUserProfile({
			   desc: "用于完善会员资料", // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
			   success: res => {
			     var userInfo = res.userInfo
				 wx.login({
				 	success: function(val) {
				 		if (val.code) {
				 			var parems = {
								code:val.code,
								'rawData[nickName]':userInfo.nickName,
								'rawData[avatarUrl]':userInfo.avatarUrl,
				 			}
				 			wxLogin(parems).then(r => {
								if(r.code == 1){
									wx.setStorageSync('accessToken', r.data.user.token)
									wx.setStorageSync('userInfo', r.data.user)
									setTimeout(function () {
									  uni.navigateBack({
									  	delta:1
									  })
									}, 600)
								}else{
									wx.showToast({
										title:res.msg,
										icon:'none'
									})
								}
				 				
				 			})
				 		} else {
				 			wx.showToast({
				 				title:res.message,
				 				icon:'none'
				 			})
				 		}
						uni.hideLoading()
				 	}
				 });
			  },
			})
		},
		// 取消
		toIndex() {
			uni.switchTab({
				url: '/pages/index/index'
			})
		},
	}
};
</script>

<style scoped>
.warrant .white {
	width: 540rpx;
	height: 521rpx;
	background-color: #fff;
	border-radius: 15rpx;
	position: fixed;
	top: 50%;
	left: 54%;
	margin-left: -299.5rpx;
	margin-top: -260.5rpx;
	z-index: 9;
}

.warrant .white .pictrue {
	background-image: url('');
	background-repeat: no-repeat;
	background-size: 100% 100%;
	width: 300rpx;
	height: 295rpx;
	margin: -80rpx auto 0 auto;
}

.warrant .white .tip {
	font-size: 30rpx;
	color: #8a8a8a;
	text-align: center;
	margin-top: 44rpx;
	padding: 0 30rpx;
}

.warrant .white .but {
	height: 80rpx;
	font-size: 30rpx;
	background-color: #5d8bf7;
	color: #fff;
	border-radius: 50rpx;
	margin-top: 50rpx;
	width: 80%;
}

.warrant .white .but::after {
	border: none;
}

.warrant .white .but:active {
	background-color: #5d8bf7;
}

.warrant .mask {
	position: fixed;
	top: 0;
	right: 0;
	left: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
}
/*按钮动画 */
.bubble {
	position: relative;
	overflow: hidden;
}
.bubble:after {
	content: '';
	background: #cdcdcd;
	position: absolute;
	width: 750rpx;
	height: 750rpx;
	left: calc(50% - 375rpx);
	top: calc(50% - 375rpx);
	opacity: 0;
	margin: auto;
	border-radius: 50%;
	transform: scale(1);
	transition: all 0.6s ease-in-out;
}
.bubble:active:after {
	transform: scale(0);
	opacity: 1;
	transition: 0s;
}
</style>
